package com.ftg.learn.chapter09.listtest;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 子列表查找
 * 编写一个函数，接受一个整数列表和一个目标整数S，
 * 找出列表中连续元素之和等于S的子列表。
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/8/16 14:27
 */

public class Sublist {

    public static void main(String[] args) {

        System.out.println("输入目标整数");
        Scanner scanner=new Scanner(System.in);
        int s=scanner.nextInt();
        List<Integer> list=new ArrayList<>();
        System.out.println("输入链表中数的个数");
        int count=scanner.nextInt();
        int num;
        System.out.println("输入数字");
        for (int i = 0; i < count; i++) {
            num= scanner.nextInt();
            list.add(num);
        }
        System.out.println(list);

        for (int i = 0; i < list.size()-1; i++) {
            if(list.get(i)+list.get(i+1)==s){
                System.out.printf("%d,%d", list.get(i),list.get(i+1));
            }
        }
    }
}
